//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include "ArffAttributeObject.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <fstream>
#include <iostream>
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#define MAX_SIZE 500000
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ArffAttributeObject::ArffAttributeObject () {

  this->type     = new String ();
  this->value    = new String ();
  
  this->toString = new String ();

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ArffAttributeObject::ArffAttributeObject (const ArffAttributeObject& arffAttributeObject) {

  this->type     = new String (arffAttributeObject.type);
  this->value    = new String (arffAttributeObject.value);
  
  this->toString = new String (arffAttributeObject.toString);

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ArffAttributeObject::ArffAttributeObject (const ArffAttributeObject* arffAttributeObject) {

  this->type     = new String (arffAttributeObject->type);
  this->value    = new String (arffAttributeObject->value);
  
  this->toString = new String (arffAttributeObject->toString);

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ArffAttributeObject::~ArffAttributeObject () {

  if (this->type)     delete this->type;
  if (this->value)    delete this->value;
  
  if (this->toString) delete this->toString;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ArffAttributeObject::Type (String* type) {

  if (type)
    *(this->type) = *type;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ArffAttributeObject::Value (String* value) {

  if (value)
    *(this->value) = *value;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//

String* ArffAttributeObject::Type (void) {

  return this->type;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ArffAttributeObject::Value (void) {

  return this->value;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ArffAttributeObject::ReadFromString (String* line) {

  if (!line) return false;
  
  return this->ReadFromString(line->Out());

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ArffAttributeObject::ReadFromString (char* line) {

  if (!line) return false;
  
  char* parts = NULL;

  if (strstr(line, "@attribute")) {
    
    if (!(parts = strtok(line, " \"\n\t\r"))) return false;
    if (!(parts = strtok(NULL, " \"\n\t\r"))) return false;
    this->value->In(parts);
    this->value->Trim();
    
    if (!(parts = strtok(NULL, " \"\n\t\r"))) return false;
    this->type->In(parts);
    this->type->Trim();
  
  }
  else return false;
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ArffAttributeObject ArffAttributeObject::operator= (const ArffAttributeObject& arffAttributeObject) {

  *(this->type)     = *(arffAttributeObject.type);
  *(this->value)    = *(arffAttributeObject.value);
  
  *(this->toString) = *(arffAttributeObject.toString);

  return *this;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
